<?php
//Author: Adam Bowman
//11/9/11 Cleaned up code to make it easier to read
//OurDatabase.class.php
//-----------------------------------
//echo "program starts now ";
//	define( 'DB_SERVER', 'localhost' );
//	define( 'DB_USER', 'root' );
//	define( 'DB_PASS', '' );
//	define( 'DB_NAME', 'lul' );

// ----------------
// DB TABLE Names
// ---------------
	define ('TBL_ADMIN', 'wms_admin');
	define ('TBL_EMPLOYER', 'wms_employer');

	class OurDatabase{
//Attributes
	private $connection;
	public $last_query;
//Methods
	function __construct(){
//$this->open_connection();
	}
public function open_connection()
{
	$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
	if( !$this->connection ){
	die("Database connection failed." . mysql_error() );
}
	else{ 
		$db_select = mysql_select_db(DB_NAME, $this->connection);
		if(!$db_select)
		{
			die("Database selection failed". mysql_error() );
		}
	}
}

public function close_connection()
{
	if( isset($this->connection) )
		{
			mysql_close( $this->connection);
			unset( $this->connection);
		}
}

// usage $result = $db->query( $sql );
public function query( $sql="" )
	{
		$this->last_query = $sql;
		$result = mysql_query($sql, $this->connection);
		$this->confirm_query ( $result );
		return $result;
	}

private function confirm_query ( $result )
	{
		if(!$result)
	{
		$output = "Database query failed ". $this->mysql_db_error() . "<br />";
		$output .= "Last Query run : " . $this->last_query;
		die( $output );
	}
}

public function mysql_db_error()
	{
		return mysql_errno() ." - ". mysql_error();
	}
	
public function num_rows( $result )
	{
		return mysql_num_rows( $result);
	}

}//end class
?> 